#!/bin/bash

set -e

TAG=entrypoint
IMAGE=nginx
IMAGE_FULL_NAME=$IMAGE:$TAG
CONTAINER_NAME=${IMAGE}_${TAG}

case $1 in
    build )
        docker build -t $IMAGE_FULL_NAME .
    ;;
    run )
        docker run -d --name $CONTAINER_NAME $IMAGE_FULL_NAME
    ;;
    start )
        docker start $CONTAINER_NAME
    ;;
    stop )
        docker stop $CONTAINER_NAME
    ;;
    exec )
        docker exec -it $CONTAINER_NAME /bin/bash
    ;;
    clean_container)
        docker stop $CONTAINER_NAME && docker rm $CONTAINER_NAME
    ;;
    cleanall)
        docker stop $CONTAINER_NAME && docker rm $CONTAINER_NAME
        docker rmi $IMAGE_FULL_NAME
    ;;
    ps)
        docker ps | grep nginx_entrypoint
    ;;
    * )
        echo 'Usage: ./tools.sh {build | run | exec| cleanall | clean_container | ps | stop | start}'
    ;;
esac



